<!--{template /module/admin/view/head}-->
<div id="left_layout">
	<div id="main_content" class="container-fluid">
		<!--{template /module/admin/view/head_nav}-->
		<div class="row-fluid">
			<div class="well widget">
				<div class="widget-header">
					<h3 class="title">{lang user.message_tpl.view.header}</h3>
				</div>
				<div class="widget-content">
					<div class="action-wrapper">
						<div class="pull-left">
							<a href="javascript:void(null);" id="btn_enable_list" class="btn btn-small" {$dispatches[operations][setup]}>{lang admin.operation.enable}</a>
							<a href="javascript:void(null);" id="btn_disable_list" class="btn btn-small" {$dispatches[operations][setup]}>{lang admin.operation.disable}</a>
							<a href="javascript:void(null);" id="btn_delete_list" class="btn btn-small" {$dispatches[operations][setup]}>{lang admin.operation.delete}</a>
							<a href="{$ADMIN_SCRIPT}/user/message/_tpl&do=add" class="btn btn-small">{lang user.message_tpl.view.operation.add}</a>
							<a href="{$ADMIN_SCRIPT}/user/message" class="btn btn-small">{lang admin.operation.go.back}</a>
						</div>
					</div>
					
					<hr/>
					<form id="frm_grid" name="frmGrid" action="{$ADMIN_SCRIPT}/user/message/_tpl" method="post">
					<table class="table table-hover">
						<thead>
							<tr>
								<th width="30"><input type="checkbox" class="fancy" name="cbxAll"/></th>
								<th width="150">{lang user.message_tpl.view.th.serial}</th>
								<th>{lang user.message_tpl.view.th.identity}</th>
					            <th width="160">{lang user.message_tpl.view.th.title}</th>
					            <th width="90">{lang user.message_tpl.view.th.username}</th>
					            <th width="120">{lang user.message_tpl.view.th.edittime}</th>
					            <th width="60">{lang user.message_tpl.view.th.status}</th>
					            <th width="90">{lang user.message_tpl.view.th.operate}</th>
							</tr>
						</thead>
						<tbody>
							<!--{loop $message_tpls $_loop $msgtpl}-->
							<tr class="item-row">
							<td>
				                <input type="checkbox" class="fancy" title="{$msgtpl[TITLE]}" name="cbxItem[]" value="{$msgtpl[MESSAGE_TPLID]}"/>
				            </td>
				            <td>
				                {$msgtpl[SERIAL]}
				            </td>
				            <td class="f10">
				            	{$msgtpl[IDENTITY]}
				            </td>
				            <td>
				            	{$msgtpl[TITLE]}
				            </td>
				            <td class="f10">
				                {$msgtpl[USERNAME]}
				            </td>
				            <td class="f10">
				                {$msgtpl[EDITTIME]}
				            </td>
				            <td>
				                <!--{if $msgtpl['ENABLED']}-->
				                {lang user.message_tpl.view.td.status.yes}
				                <!--{else}-->
				                {lang user.message_tpl.view.td.status.no}
				                <!--{/if}-->
				            </td>
				            <td class="center">
				            	<a class="btn btn-mini btn-primary" href="{$ADMIN_SCRIPT}/user/message/_tpl&do=update&id={$msgtpl[MESSAGE_TPLID]}">{lang admin.operation.edit}</a>
				                <a class="btn btn-mini btn-delete" title="{$msgtpl[TITLE]}" data="{$msgtpl[MESSAGE_TPLID]}" href="javascript:void(null);">{lang admin.operation.delete}</a>
				            </td>
				            </tr>
				            <!--{/loop}-->
				            <!--{if count($message_tpls) == 0}-->
					        <tr>
					            <td colspan="7">
					                * {lang admin.operation.empty}
					            </td>
					        </tr>
					        <!--{/if}-->
						</tbody>
					</table>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>

<script>
$(function(){
	$('.fancy').uniform();
	
	$('#btn_submit').click(function(){
		$('#frm_grid').submit();
	});
	
	$('#btn_enable_list').click(function(){
		if($("#frm_grid input[name='cbxItem[]']:checked").length > 0){
			var tempHTML = '<p>';
			$("#frm_grid input[name='cbxItem[]']:checked").each(function(){
				tempHTML += $(this).attr('title') + '； ';
			});
			
			tempHTML += '</p>';
			
			$.dialog({submit:'{lang admin.operation.enable}', message:'<p>{lang user.message_tpl.view.operation.enable.messagee}</p>' + tempHTML, callback:function(){
				$('#modal_dialog .btn-primary').click(function(){
					$('#frm_grid').attr('action', '{$ADMIN_SCRIPT}/user/message/_tpl&cmd=enable_list');
					$('#frm_grid').submit();
				});
			}});
		}else $.dialog({message:'{lang user.message_tpl.view.operation.empty}'});
	});
	
	$('#btn_disable_list').click(function(){
		if($("#frm_grid input[name='cbxItem[]']:checked").length > 0){
			var tempHTML = '<p>';
			$("#frm_grid input[name='cbxItem[]']:checked").each(function(){
				tempHTML += $(this).attr('title') + '； ';
			});
			
			tempHTML += '</p>';
			
			$.dialog({submit:'{lang admin.operation.disable}', message:'<p>{lang user.message_tpl.view.operation.disable.messagee}</p>' + tempHTML, callback:function(){
				$('#modal_dialog .btn-primary').click(function(){
					$('#frm_grid').attr('action', '{$ADMIN_SCRIPT}/user/message/_tpl&cmd=disable_list');
					$('#frm_grid').submit();
				});
			}});
		}else $.dialog({message:'{lang user.message_tpl.view.operation.empty}'});
	});
	
	$('#btn_delete_list').click(function(){
		if($("#frm_grid input[name='cbxItem[]']:checked").length > 0){
			var tempHTML = '<p>';
			$("#frm_grid input[name='cbxItem[]']:checked").each(function(){
				tempHTML += $(this).attr('title') + '； ';
			});
			
			tempHTML += '</p>';
			
			$.dialog({submit:'{lang admin.operation.delete}', message:'<p>{lang user.message_tpl.view.operation.delete.message}</p>' + tempHTML, callback:function(){
				$('#modal_dialog .btn-primary').click(function(){
					$('#frm_grid').attr('action', '{$ADMIN_SCRIPT}/user/message/_tpl&cmd=delete_list');
					$('#frm_grid').submit();
				});
			}});
		}else $.dialog({message:'{lang user.message_tpl.view.operation.empty}'});
	});
	
	$("#frm_grid input[name='cbxAll']").click(function(){
		if(this.checked){
			$('#frm_grid .item-row').addClass('warning');
			$("#frm_grid input[name='cbxItem[]']").attr('checked', true).parent().addClass('checked');
		}else{
			$('#frm_grid .item-row').removeClass('warning');
			$("#frm_grid input[name='cbxItem[]']").attr('checked', false).parent().removeAttr('class');
		}
	});
	
	$("#frm_grid input[name='cbxItem[]']").click(function(){
		if(this.checked) $(this).parent().parent().parent().parent().addClass('warning');
		else $(this).parent().parent().parent().parent().removeClass('warning');
	});
	
	$('#frm_grid .btn-delete').click(function(){
		var msgtplid = $(this).attr('data');
		var tempHTML = '<p>' + $(this).attr('title') + '； </p>';
		$.dialog({submit:'{lang admin.operation.delete}', message:'<p>{lang user.message_tpl.view.operation.delete.message}</p>' + tempHTML, callback:function(){
			$('#modal_dialog .btn-primary').click(function(){
				$('#frm_grid').attr('action', '{$ADMIN_SCRIPT}/user/message/_tpl&cmd=delete&id=' + msgtplid);
				$('#frm_grid').submit();
			});
		}});
	});
});
</script>
<!--{template /module/admin/view/foot}-->